<?php

class Filters_protoFilter {
  protected $ctx;
  protected $fields = array();
  protected $filterPattern;
  protected $filterForm;
  protected $data;
  
  public function __construct( $ctx ) {
    $this->ctx = $ctx;
  }
  
  public function getFilterFields() {
    return $this->fields;
  }
  
  public function getFilterForm( $params ) {
    // -- old theme HACK : 2008-05-21 : lucky -- {{{
		$community_skin = 'platonica';
		$tpl = $this->ctx->tpl;
		$community_model = $this->ctx->mm->getModel("Community");
		$community_model->setDefaultSkin($community_skin);
		$tpl->setSkin($community_skin);
		$views_php = $tpl->findFile('', 'views', $tpl->_skin, 'php');
		unset ($config);
		include $views_php; // got $config
		$this->ctx->rh->views->setViewConfig($config);
		// -- old theme HACK : 2008-05-21 : lucky -- }}}

    
    $view = $this->ctx->rh->views->findByName( $this->filterForm );
    
    if ( !empty($params) && isset($params['oid']) ) {
      $object = $this->ctx->store->getObject( $params['oid'] );
      foreach ( $this->fields as $field ) {
        if ( isset($object->data[$field]) && !empty($object->data[$field]) ) {
          $view->data[$field] = htmlspecialchars(stripslashes(trim($object->data[$field])));
        }
      }
    }
    
    return $view->getContent();
  }
  
  public function getFilterPattern( $oid ) {
    $view = $this->ctx->rh->views->findByName( $this->filterPattern );
    
    $object = $this->ctx->store->getObject( $oid );
    
    foreach ( $this->fields as $field ) {
      $view->data[$field] = $object->data[$field];
    }

    return $view->getContent();
  }
  
  public function setData( $data ) {
    $this->data = $data;
  }
}